﻿using UnityEngine;
using System.Collections;

public class FX_rotate_loop : MonoBehaviour {

	public bool bAlignWorld = false;
	public bool loop = false;
	public Vector3 vRotationValue = new Vector3 (0, 0, 0);
	public float duration = 1.0f;

	
	Quaternion vOriginalRotation;
	
	float timer = 0;
	
	[SerializeField]
	AnimationCurve curveX;
	[SerializeField]
	AnimationCurve curveY;
	[SerializeField]
	AnimationCurve curveZ;
	
	void Start(){
		vOriginalRotation = transform.rotation;
	}
	void Update ()
	{
		
		Vector3 rotation;
		rotation.x = curveX.Evaluate(timer)* vRotationValue.x;
		rotation.y = curveY.Evaluate(timer)* vRotationValue.y;
		rotation.z = curveZ.Evaluate(timer)* vRotationValue.z;
		
		if (bAlignWorld) {
			transform.rotation = Quaternion.Euler (rotation);
		} else {
			transform.rotation = Quaternion.Euler (rotation)* vOriginalRotation;
		}
		//transform.Rotate(vRotationValue.x,vRotationValue.y*Time.deltaTime*rotation.y,vRotationValue.z,(bWorldSpace ? Space.World : Space.Self));
		
		timer += Time.deltaTime/duration;

		if (loop) {
			if(timer >= 1.0f){
				timer = 0f;
			}
		}
	}
}
